<div class="layuimini-container layuimini-page-anim">
	<div class="layuimini-main">

		<fieldset class="table-search-fieldset">
			<legend>搜索信息</legend>
			<div style="margin: 10px 10px 10px 10px">
				<form class="layui-form layui-form-pane" action="">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">用户名</label>
							<div class="layui-input-inline">
								<input type="text" name="userName" autocomplete="off"
									class="layui-input">
								<input type="hidden" name="type" value="1" />
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">手机号</label>
							<div class="layui-input-inline">
								<input type="text" name="tel" autocomplete="off"
									class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">性别</label>
							<div class="layui-input-inline">
								<select id="sex" name="sex" lay-filter="st">
									<option value="">全部</option>
									<option value="男">男</option>
									<option value="女">女</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">状态</label>
							<div class="layui-input-inline">
								<select id="status" name="status" lay-filter="st"
									item_url="/item_lib/svr_status.json" item-filter="1,-1">
									<option value="">全部</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">用户角色</label>
							<div class="layui-input-inline">
					<select id="roles" name="roles" lay-filter="st"
						item_url="/item_lib/roles.json" item-filter="8,9,12">
									<option value="">全部</option>
					</select>
							</div>
						</div>
						<div class="layui-inline">
							<button type="submit" class="layui-btn layui-btn-primary"
								lay-submit lay-filter="data-search-btn">
								<i class="layui-icon"></i>搜 索
							</button>
						</div>
					</div>
				</form>
			</div>
		</fieldset>

		<table class="layui-hide" id="currentTableId"
			lay-filter="currentTableFilter"></table>
		<script type="text/html" id="switchStatus">
			  <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="正常|锁定" lay-filter="svrStatus" {{ d.status == 1 ? 'checked' : '' }}>
		</script>

		<script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="reSetPass">重置</a>
        </script>

	</div>
</div>


<script>
	
    layui.use(['form', 'table','miniPage','element','common'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
             layarea = layui.layarea,
            miniPage = layui.miniPage;
        
        //初始化所有select 
        

        table.render({
            elem: '#currentTableId',
            url: '/user/',
           // method:'post',
            //contentType:'application/json',
            where:{type:1},
            toolbar: '<div class="layui-btn-container"></div>',
            defaultToolbar: [ 'exports', 'print'],
            cols: [[
                //{type: "checkbox", width: 30},
                {field: 'id', width: 60, title: 'ID', sort: false},
                {field: 'userName', minWidth: 100, title: '用户名称'}, 
                {field: 'sex', minWidth: 60, title: '性别', sort: false},
                {field: 'tel', width: 120, title: '手机'},
                {field: 'email', width: 150, title: '邮箱'},
                {field: 'roles', width: 120, title: '角色'},
                {field: 'status', width: 100, title: '状态', templet: '#switchStatus', unresize: true	},
                {field: 'createTime', width: 145, title: '创建时间'},
                //{field: 'modifyTime', width: 145, title: '更新时间',sort: true},
                {fixed: 'right',  title:'重置密码',minWidth: 80, toolbar: '#currentTableBar', align: "center"}
            ]],
            //limits: [20, 30, 50, 100],
            //limit: 20,
            //page: true,
            //skin: 'line'
        });
		    
        form.on('submit(data-search-btn)', function (data) {
            /*var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });*/

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                },
                 where:  data.field
            	});
            return false;
        });

		//监听锁定操作
  		form.on('switch(svrStatus)', function(obj){
  			var svrSt=-1
  			var svrId=this.value
  			if (obj.elem.checked)
  				svrSt=1
  			$.ajax({
				url: "/user/status/"+svrId+"/"+svrSt,
				type: 'get',
				async: true,
				dataType: 'json',
				success: function(data) {
					layer.tips("后台更新状态成功["+data.count+"]", obj.othis);
				}
			});
  		});

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
             if (obj.event === 'reSetPass') {
                layer.confirm('确定重置['+data.userName+']的密码,重置后旧密码作废,新默认密码为"88888888",请务必提醒用户尽快登录修改默认密码', function (index) {
		        	$.ajax({
						url: "/user/password/"+obj.data.id,
						type: 'get',
						async: false,
						dataType: 'json',
						success: function(data) {
							layer.alert('新默认密码为"88888888",请务必提醒用户尽快登录修改默认密码', {
                				title: '密码重置成功'
            				});
							// 关闭弹出层                   		
                    		layer.close(index);
 						}
					});
                });
            }
        });

    //初始化选择框    
	layui.common.initSelect();
    });
</script>